---
title: Extensive Kitchen-Terraform
---

<div
  class="container"
  style="padding-top: 0px;"
>
  <div class="row">
    <div class="col-12">
      <div class="jumbotron">
        <h1 class="display-3">Extensive Kitchen-Terraform</h1>
        <p class="lead">
          A detailed review of the features of Kitchen-Terraform.
        </p>
        <div class="float-right">Author: Aaron Lane</div>
      </div>
    </div>
  </div>
  <div class="row">
    <div class="col-4">
      <div
         class="list-group"
         id="list-tab"
         role="tablist"
      >
        <a
          aria-controls="list-one"
          class="list-group-item list-group-item-action active"
          data-toggle="list"
          href="#list-one"
          id="list-one-list"
          role="tab"
        >
          1. Introduction
        </a>
        <a
          aria-controls="list-two"
          class="list-group-item list-group-item-action"
          data-toggle="list"
          href="#list-two"
          id="list-two-list"
          role="tab"
        >
          2. Configure Amazon Web Services
        </a>
        <a
          aria-controls="list-three"
          class="list-group-item list-group-item-action"
          data-toggle="list"
          href="#list-three"
          id="list-three-list"
          role="tab"
        >
          3. Create InSpec Profile
        </a>
        <a
          aria-controls="list-four"
          class="list-group-item list-group-item-action"
          data-toggle="list"
          href="#list-four"
          id="list-four-list"
          role="tab"
        >
          4. Generate SSH Key
        </a>
        <a
          aria-controls="list-five"
          class="list-group-item list-group-item-action"
          data-toggle="list"
          href="#list-five"
          id="list-five-list"
          role="tab"
        >
          5. Create Test Fixture Terraform Configuration
        </a>
        <a
          aria-controls="list-six"
          class="list-group-item list-group-item-action"
          data-toggle="list"
          href="#list-six"
          id="list-six-list"
          role="tab"
        >
          6. Create Terraform Module
        </a>
        <a
          aria-controls="list-seven"
          class="list-group-item list-group-item-action"
          data-toggle="list"
          href="#list-seven"
          id="list-seven-list"
          role="tab"
        >
          7. Create Test Kitchen Configuration
        </a>
        <a
          aria-controls="list-eight"
          class="list-group-item list-group-item-action"
          data-toggle="list"
          href="#list-eight"
          id="list-eight-list"
          role="tab"
        >
          8. Test Terraform Module
        </a>
      </div>
    </div>
    <div class="col-8">
      <div
        class="tab-content"
        id="nav-tabContent"
      >
        <div
          aria-labelledby="list-one-list"
          class="tab-pane fade show active"
          id="list-one"
          role="tabpanel"
        >
          This tutorial provides a detailed review of the features of Kitchen-Terraform by developing a Terraform module
          which configures resources on the
          <%= link_to(
                "Amazon Web Services (AWS)",
                "https://aws.amazon.com/"
              ) %>
          platform.
          <br><br>
          Kitchen-Terraform is assumed to be installed on the development system according to the instructions in the
          <%= link_to(
                "Kitchen-Terraform ReadMe",
                "https://github.com/newcontext-oss/kitchen-terraform/blob/master/README.md#installation"
              ) %>.
          <br><br>
          The files and scripts shown in this tutorial are sourced from
          a functional
          <%= link_to(
                "example project",
                "https://github.com/newcontext-oss/kitchen-terraform/tree/master/examples/extensive_kitchen_terraform"
              ) %>
          in the Kitchen-Terraform repository.
          <br><br>
          Any issues with this tutorial should be reported in the Kitchen-Terraform
          <%= link_to(
                "issue tracker",
                "https://github.com/newcontext-oss/kitchen-terraform/issues"
              ) %>.
        </div>
        <div
          aria-labelledby="list-two-list"
          class="tab-pane fade show"
          id="list-two"
          role="tabpanel"
        >
          This tutorial creates AWS resources using the
          <%= link_to(
                "Terraform AWS Provider",
                "https://www.terraform.io/docs/providers/aws/index.html"
              ) %>
          so
          <%= link_to(
                "registration of an AWS account",
                "https://portal.aws.amazon.com/gp/aws/developer/registration/index.html"
              ) %>
          is required.
          <br><br>
          The
          <%= link_to(
                "AWS Command Line Interface (CLI)",
                "https://aws.amazon.com/documentation/cli/"
              ) %>
          must be installed and configured with the credentials of the AWS account by following the
          <%= link_to(
                "AWS CLI Quick Configuration",
                "https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-quick-configuration"
              ) %>
          instructions.
          <br><br>
          The JSON filtering tool
          <%= link_to(
                "jq",
                "https://stedolan.github.io/jq/"
              ) %>
          must be installed to enable the parsing of output from the AWS CLI in Bash scripts.
          <br><br>
          <%= link_to(
                "IAM users",
                "https://console.aws.amazon.com/iam/home#users"
              ) %>
          with API keys must be created in the us-east-1 region and the us-west-2 region. Those IAM users must be
          authorized to manage a variety of AWS resources, which can be accomplished by adding an inline custom
          policy like the following example to the IAM users.
          <br></br>
          <% read_example_file(
               language: "json",
               path: "extensive_kitchen_terraform/iam_user_policy.json",
             ) do %>
<%= lines %>
          <% end %>
        </div>
        <div
          aria-labelledby="list-three-list"
          class="tab-pane fade show"
          id="list-three"
          role="tabpanel"
        >
          Prepare the
          <%= link_to(
                "InSpec profile",
                "https://www.inspec.io/docs/reference/profiles/"
              ) %>
          by mimicking the following Bash script.
          <% read_example_file(
               language: "bash",
               path: "extensive_kitchen_terraform/prepare_inspec_profile.bash",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the InSpec profile description file,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/integration/extensive_suite/inspec.yml
          </p>, to match the following example.
          <% read_example_file(
               language: "yml",
               path: "extensive_kitchen_terraform/test/integration/extensive_suite/inspec.yml",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the InSpec attributes control,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/integration/extensive_suite/controls/inspec_attributes.rb
          </p>
          , to match the following example.
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/integration/extensive_suite/controls/inspec_attributes.rb",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the operating system control,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/integration/extensive_suite/controls/operating_system.rb
          </p>
          , to match the following example.
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/integration/extensive_suite/controls/operating_system.rb",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the attributes for the centos test,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/integration/extensive_suite/centos_attributes.yml
          </p>
          , to match the following example.
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/integration/extensive_suite/centos_attributes.yml",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>          
          Populate the attributes for the ubuntu test,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/integration/extensive_suite/ubuntu_attributes.yml
          </p>
          , to match the following example.
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/integration/extensive_suite/ubuntu_attributes.yml",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the reachable other host control,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/integration/extensive_suite/controls/reachable_other_host.rb
          </p>
          , to match the following example.
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/integration/extensive_suite/controls/reachable_other_host.rb",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the state file control,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/integration/extensive_suite/controls/state_file.rb
          </p>
          , to match the following example.
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/integration/extensive_suite/controls/state_file.rb",
             ) do %>
<%= lines %>
          <% end %>
        </div>
        <div
          aria-labelledby="list-four-list"
          class="tab-pane fade"
          id="list-four"
          role="tabpanel"
        >
          Mimic the following Bash script to generate an authentication key for SSH to be used by InSpec when
          authenticating with the AWS EC2 instances under test.
          <br><br>
          <% read_example_file(
               language: "bash",
               path: "extensive_kitchen_terraform/generate_ssh_key.bash",
             ) do %>
<%= lines %>
          <% end %>
        </div>
        <div
          aria-labelledby="list-five-list"
          class="tab-pane fade"
          id="list-five"
          role="tabpanel"
        >
          Using a test fixture Terraform configuration to invoke the Terraform module under test provides two
          advantages. First, it enables the expansion of the variable interface and the output interface
          of the module to better support testing without polluting the core logic. Second, it provides an opportunity
          to test the user experience of the module and identify areas of the design that can be improved or simplified.
          <br><br>
          Prepare the configuration by mimicking the following Bash script.
          <% read_example_file(
               language: "bash",
               path: "extensive_kitchen_terraform/prepare_test_fixture_terraform_configuration.bash",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the variables file,
          <p class="font-weight-bold" style="color: #32c850; display: inline;">test/fixtures/wrapper/variables.tf</p>, to match the following example.
          <br><br>
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/fixtures/wrapper/variables.tf",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the main file,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/fixtures/wrapper/main.tf
          </p>
          , to match the following example.
          <br><br>
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/fixtures/wrapper/main.tf",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the outputs file,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            test/fixtures/wrapper/outputs.tf
          </p>
          , to match the following example.
          <br><br>
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/test/fixtures/wrapper/outputs.tf",
             ) do %>
<%= lines %>
          <% end %>
        </div>
        <div
          aria-labelledby="list-six-list"
          class="tab-pane fade"
          id="list-six"
          role="tabpanel"
        >
          The Terraform module is the actual artifact under test. The design of the module is informed by the InSpec
          profile and the fixture configuration.
          <br><br>
          Prepare the module by mimicking the following Bash script.
          <% read_example_file(
               language: "bash",
               path: "extensive_kitchen_terraform/prepare_terraform_module.bash",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the variables file,
          <p class="font-weight-bold" style="color: #32c850; display: inline;">variables.tf</p>, to match the following example.
          <br><br>
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/variables.tf",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the main file,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            main.tf
          </p>
          , to match the following example.
          <br><br>
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/main.tf",
             ) do %>
<%= lines %>
          <% end %>
          <br><br>
          Populate the outputs file,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            outputs.tf
          </p>
          , to match the following example.
          <br><br>
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/outputs.tf",
             ) do %>
<%= lines %>
          <% end %>
        </div>
        <div
          aria-labelledby="list-seven-list"
          class="tab-pane fade"
          id="list-seven"
          role="tabpanel"
        >
          Populate the Test Kitchen configuration file,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            kitchen.yml
          </p>
          , to match the following example.
          <br><br>
          <% read_example_file(
               language: "yml",
               path: "extensive_kitchen_terraform/kitchen.yml",
             ) do %>
<%= lines %>
          <% end %>
        </div>
        <div
          aria-labelledby="list-eight-list"
          class="tab-pane fade"
          id="list-eight"
          role="tabpanel"
        >
          Populate the Bundler dependency file,
          <p
            class="font-weight-bold"
            style="color: #32c850; display: inline;"
          >
            Gemfile
          </p>,
          to match the following example.
          <br><br>
          <% read_example_file(
               language: "ruby",
               path: "extensive_kitchen_terraform/Gemfile",
             ) do %>
<%= lines %>
          <% end %>
          Install the declared Ruby gem dependencies by mimicking the following Bash script.
          <br><br>
          <% read_example_file(
               language: "bash",
               path: "extensive_kitchen_terraform/install_ruby_gem_dependencies.bash",
             ) do %>
<%= lines %>
          <% end %>
          Test the Terraform module using multiple platforms by mimicking the following Bash script.
          <br><br>
          <% read_example_file(
               language: "bash",
               path: "extensive_kitchen_terraform/execute_kitchen_terraform.bash",
             ) do %>
<%= lines %>
          <% end %>
        </div>
      </div>
    </div>
  </div>
</div>
